//
//  YCArticlelistModel.m
//  YCSchool
//
//  Created by Yanglixia on 16/5/7.
//  Copyright © 2016年 yanglinxia. All rights reserved.
//

#import "YCArticlelistModel.h"

@implementation YCArticlelistModel


- (NSArray *)photoArray
{
    if (!_photoArray) {
        
        YCAtrticleImgsSubModel *model = self.imgs.a0;
        if (model) {
            NSString *urlString = [YCAPIBaseUrl stringByAppendingString:model.url_sql];
            _photoArray = @[urlString];//
        } else {
            _photoArray = [NSArray array];
        }
    }
    return _photoArray;
}

- (CGFloat)talentHeight
{
    CGFloat height = 0;
    
    if (self.photoArray.count == 0)
    {
        height = 0;
    }
    else if (self.photoArray.count == 1)
    {
        height = 160;
    }
    else if (self.photoArray.count >1 && self.photoArray.count <4)
    {
        height = 70;
    }
    else if (self.photoArray.count >3 && self.photoArray.count <7)
    {
        height = 150;
    }
    else if (self.photoArray.count > 6)
    {
        height = 230;
    }
    
    return height;
}


- (CGFloat)appearanceHeight
{
    CGFloat width = kScreenWidth - 75 - 15;
    CGFloat height = 0;
    
    if (self.photoArray.count == 1)
    {
        height = width;
    }
    else if (self.photoArray.count == 2)
    {
        height = (width-5)/2+20;
    }
    else if (self.photoArray.count == 3)
    {
        height = (width-10)/3*2+5+10;
    }
    else if (self.photoArray.count == 4)
    {
        height = width;
    }
    else if (self.photoArray.count == 5)
    {
        height = (width-5)/2+(width-5-10)/3+15;
    }
    else if (self.photoArray.count == 6)
    {
        height = width;
    }
    
    return height;
}


- (CGFloat)l_contentHeight
{
    __block CGFloat lineSpace = 3;
    [YCAdapter performOtherBlock:^{
        lineSpace = 3;
    } IPhone6Block:^{
        lineSpace = 6;
    } IPhone6pBlock:^{
        lineSpace = 8;
    }];
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:lineSpace];
    //    paragraphStyle.lineBreakMode =  NSLineBreakByCharWrapping;
    
    NSMutableAttributedString *content = [[NSMutableAttributedString alloc] initWithString:self.content attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:[UIFont systemFontOfSize:15]}];
    
    CGFloat contentHeight = [content boundingRectWithSize:CGSizeMake(kScreenWidth-85, CGFLOAT_MAX)
                                                  options:NSStringDrawingUsesLineFragmentOrigin
                                                  context:nil].size.height;
    
    return contentHeight;
}

/**
 *  日期处理
 */
- (NSString *)yc_dateProcessWithAddTime:(NSString *)addtime_str
{
    NSString *newString;
    NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    fmt.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    NSDate *createdAtDate = [fmt dateFromString:addtime_str];
    if (createdAtDate.yc_isInThisYear) { // 今年
        if (createdAtDate.yc_isInYesterday) { // 昨天
            fmt.dateFormat = @"昨天 HH:mm:ss";
            newString = [fmt stringFromDate:createdAtDate];
        } else if (createdAtDate.yc_isInToday) { // 今天
            NSDateComponents *cmps = [[NSCalendar yc_calendar] components:NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond fromDate:createdAtDate toDate:[NSDate date] options:0];
            if (cmps.hour >= 1) { // 时间间隔 >= 1小时
                newString = [NSString stringWithFormat:@"%zd小时前", cmps.hour];
            } else if (cmps.minute >= 1) { // 1小时 > 时间间隔 >= 1分钟
                newString = [NSString stringWithFormat:@"%zd分钟前", cmps.minute];
            } else { // 1分钟 > 时间间隔
                newString = @"刚刚";
            }
        } else { // 今年的其他日子
            fmt.dateFormat = @"MM-dd HH:mm:ss";
            newString = [fmt stringFromDate:createdAtDate];
        }
    } else { // 非今年
        newString = self.addtime_str;
    }
    
    return newString;
}


@end
